Skip to content

test(pt-expt): add .pte and .pt2 tests for dp convert-backend#5384

Queued
wanghan-iapcm wants to merge 2 commits intodeepmodeling:masterfrom
wanghan-iapcm:fix-convert-backend-pte-tests
Queued

test(pt-expt): add .pte and .pt2 tests for dp convert-backend#5384
wanghan-iapcm wants to merge 2 commits intodeepmodeling:masterfrom
wanghan-iapcm:fix-convert-backend-pte-tests

Conversation

@wanghan-iapcm
Copy link
Copy Markdown
Collaborator

@wanghan-iapcm wanghan-iapcm commented Apr 7, 2026

Summary

  • Add .pte and .pt2 to parameterized extensions in test_models.py to verify convert-backend works for the pt_expt exportable formats
  • Switch fparam_aparam model (1 atom type) from type_one_side=False to True (with ndim 2→1), which is equivalent for single-type models but enables pt_expt export
  • Skip se_e2_a/se_e2_r for .pte/.pt2type_one_side=False with multiple types triggers GuardOnDataDependentSymNode in make_fx (data-dependent indexing in NetworkCollection(ndim=2))
  • Skip test_descriptor and test_fitting_last_layer for .pte/.pt2 (not implemented in pt_expt DeepEval)

Test plan

  • python -m pytest source/tests/infer/test_models.py -v — 55 passed, 67 skipped
  • python -m pytest source/tests/infer/test_models.py -v -k "pte or pt2" — 12 passed (fparam_aparam), rest skipped
  • Existing .pb/.pth tests unaffected

Summary by CodeRabbit

  • Tests
    • Updated test case configurations with adjusted model descriptor and embedding parameters
    • Extended test suite parameterization to support additional model file formats (.pte, .pt2)
    • Reorganized model compatibility skip conditions for improved test structure and maintainability
    • Added special handling when loading certain model formats to ensure stable device behavior during tests

Add pt_expt backend (.pte/.pt2) to the parameterized extensions in
test_models.py to verify convert-backend works for the new exportable
formats.

The fparam_aparam model (1 atom type) is switched from type_one_side=False
to type_one_side=True (with ndim 2→1), which is equivalent for single-type
models but enables pt_expt export. Models with type_one_side=False and
multiple types (se_e2_a, se_e2_r) are skipped for .pte/.pt2 as make_fx
cannot trace data-dependent indexing in NetworkCollection(ndim=2).
@github-actions github-actions bot added the Python label Apr 7, 2026
@wanghan-iapcm wanghan-iapcm requested a review from njzjz April 7, 2026 13:49
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 792e9aba-e337-42ff-a61f-10da7a5aa99a

📥 Commits

Reviewing files that changed from the base of the PR and between 34d4cb5 and 281989d.

📒 Files selected for processing (1)
  • source/tests/infer/test_models.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/tests/infer/test_models.py

📝 Walkthrough

Walkthrough

Updates test configurations and the test suite to add pt-expt backend support (.pte, .pt2), adjust embedding dimensionality, and toggle type_one_side flags in test YAMLs; test skip logic and model-loading device handling were centralized in setUpClass().

Changes

Cohort / File(s) Summary
YAML Test Configuration Updates
source/tests/infer/fparam_aparam-testcase.yaml, source/tests/infer/fparam_aparam.yaml, source/tests/infer/fparam_aparam_default.yaml
Changed descriptor embedding ndim from 21 and set type_one_side from false/Falsetrue/True in descriptor and fitting sections for type: se_e2_a.
Test Suite Backend & Loading Changes
source/tests/infer/test_models.py
Added .pte and .pt2 extensions to parameterized tests; moved skip logic into setUpClass() to conditionally skip pt-expt combos; added temporary torch.set_default_device(None) handling during .pt2 model loading; expanded test skip cases for descriptor and last-layer fitting tests.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant TestCase as Case.get_model()
    participant Torch as torch
    participant ModelLoader

    TestRunner->>TestCase: setUpClass()
    TestCase->>Torch: check INSTALLED_PT_EXPT
    alt pt-expt supported
        TestRunner->>Torch: torch.set_default_device(None)
        TestRunner->>ModelLoader: load model `.pt2`/`.pte`
        ModelLoader-->>TestRunner: model object
        TestRunner->>Torch: restore previous default device
    else not supported
        TestRunner->>TestRunner: skip pt-expt tests
    end
    TestRunner->>ModelLoader: run descriptor & fitting tests (with updated YAML params)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

new feature

Suggested reviewers

  • njzjz
  • iProzd
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding .pte and .pt2 test support for the pt-expt backend in convert-backend tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
source/tests/infer/test_models.py (1)

42-45: Prefer deriving the pt_expt skip from fixture metadata.

The hard-coded ("se_e2_a", "se_e2_r") list will stay stale the next time a fixture is made exportable. The fixture already carries model_def_script.descriptor.type_one_side, so reading the skip condition from case would keep this gate aligned with the actual model data instead of the testcase key.

♻️ Suggested refactor
     `@classmethod`
     def setUpClass(cls) -> None:
         key, extension = cls.param
         if extension in (".pte", ".pt2") and not INSTALLED_PT_EXPT:
             raise unittest.SkipTest("pt_expt backend not installed")
-        if key in ("se_e2_a", "se_e2_r") and extension in (".pte", ".pt2"):
+        case = get_cases()[key]
+        descriptor = (case.model_def_script or {}).get("descriptor", {})
+        if (
+            extension in (".pte", ".pt2")
+            and descriptor.get("type") in {"se_e2_a", "se_e2_r"}
+            and not descriptor.get("type_one_side", False)
+        ):
             raise unittest.SkipTest(
                 "type_one_side=False is not supported for pt_expt export"
             )
         if key == "se_e2_r" and extension == ".pth":
             raise unittest.SkipTest(
                 "se_e2_r type_one_side is not supported for PyTorch models"
             )
-        cls.case = get_cases()[key]
+        cls.case = case
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/tests/infer/test_models.py` around lines 42 - 45, Replace the
hard-coded key check with a metadata-driven condition: instead of testing if key
in ("se_e2_a", "se_e2_r"), read the fixture's descriptor via the test case
(e.g., case.model_def_script.descriptor.type_one_side) and if that value is
False and extension is in (".pte", ".pt2") raise unittest.SkipTest; update the
conditional that currently uses variables key and extension to use
case.model_def_script.descriptor.type_one_side for the gate so the skip stays in
sync with fixture metadata.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@source/tests/infer/test_models.py`:
- Around line 42-45: Replace the hard-coded key check with a metadata-driven
condition: instead of testing if key in ("se_e2_a", "se_e2_r"), read the
fixture's descriptor via the test case (e.g.,
case.model_def_script.descriptor.type_one_side) and if that value is False and
extension is in (".pte", ".pt2") raise unittest.SkipTest; update the conditional
that currently uses variables key and extension to use
case.model_def_script.descriptor.type_one_side for the gate so the skip stays in
sync with fixture metadata.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75ef918e-5c9d-4fdd-a70c-1ed85d0f074f

📥 Commits

Reviewing files that changed from the base of the PR and between 52792f0 and 34d4cb5.

📒 Files selected for processing (4)
  • source/tests/infer/fparam_aparam-testcase.yaml
  • source/tests/infer/fparam_aparam.yaml
  • source/tests/infer/fparam_aparam_default.yaml
  • source/tests/infer/test_models.py

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.44%. Comparing base (efc27cf) to head (281989d).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5384      +/-   ##
==========================================
- Coverage   82.38%   80.44%   -1.95%     
==========================================
  Files         812      814       +2     
  Lines       83611    84438     +827     
  Branches     4091     4050      -41     
==========================================
- Hits        68882    67922     -960     
- Misses      13508    15292    +1784     
- Partials     1221     1224       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wanghan-iapcm wanghan-iapcm changed the title test: add .pte and .pt2 tests for dp convert-backend test(pt-expt): add .pte and .pt2 tests for dp convert-backend Apr 8, 2026
tests/pt/__init__.py may set a fake default device for CPU fallback,
which poisons AOTInductor compilation. Temporarily clear the default
device before converting to .pt2, matching the pattern used in
test_change_bias.py.
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Apr 8, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 8, 2026
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants